package com.tudouji.project.bill.controller;

import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.interceptor.annotation.RepeatSubmit;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.bill.domain.Recharge;
import com.tudouji.project.bill.service.IRechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充值报表Controller
 *
 * @author wf
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/bill/recharge")
public class RechargeController extends BaseController
{
    @Autowired
    private IRechargeService rechargeService;

    /**
     * 查询充值报表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Recharge recharge, String status, String functionType)
    {
//        startPage();
        List<Recharge> list = rechargeService.selectRechargeList(recharge, status, functionType);
        return getDataTable(list);
    }

    /**
     * 导出充值报表列表
     */
    @Log(title = "充值报表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Recharge recharge, String status, String functionType)
    {
        List<Recharge> list = rechargeService.selectRechargeList(recharge, status, functionType);
        ExcelUtil<Recharge> util = new ExcelUtil<Recharge>(Recharge.class);
        return util.exportExcel(list, "recharge");
    }

    /**
     * 获取充值报表详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rechargeService.selectRechargeByNewId(id));
    }

    /**
     * 新增充值报表
     */
    @PreAuthorize("@ss.hasPermi('bill:recharge:add')")
    @Log(title = "充值报表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Recharge recharge)
    {
        return toAjax(rechargeService.insertRecharge(recharge));
    }

    /**
     * 修改充值报表
     */
    @PreAuthorize("@ss.hasPermi('bill:recharge:edit')")
    @Log(title = "充值报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Recharge recharge)
    {
        return toAjax(rechargeService.updateRecharge(recharge));
    }

    /**
     * 删除充值报表
     */
    @PreAuthorize("@ss.hasPermi('bill:recharge:remove')")
    @Log(title = "充值报表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(rechargeService.deleteRechargeByIds(guids));
    }

    /**
     * 发起
     **/
    @RepeatSubmit
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Recharge entity, Long deptId, String fileIds, @RequestParam(required = false)Long taskid
            , @RequestParam(required = false)String opinion) {
        return rechargeService.save(entity, deptId, fileIds, taskid, opinion);
    }

    /**
     * 审批
     **/
    @RepeatSubmit
    @PostMapping("/approval")
    public AjaxResult  approval(Long id,Long taskid,String opinion,String fileIds){
        return rechargeService.approval(id,taskid,opinion,fileIds);
    }

    /**
     * 入账
     **/
    @RepeatSubmit
    @PostMapping("/recharge")
    public AjaxResult  recharge(Long id,Long taskid,String opinion,String fileIds){
        return rechargeService.recharge(id,taskid,opinion,fileIds);
    }

    @RepeatSubmit
    @Log(title = "拒绝", businessType = BusinessType.OTHER)
    @PostMapping("/refuse")
    public AjaxResult refuse(Long taskid,Long id,String opinion,String fileIds,Long refuseNodeid,Long backUserid){
        return rechargeService.refuse(id, fileIds, opinion, taskid,refuseNodeid,backUserid);
    }

    /**
     * 微信--删除
     */
    @RepeatSubmit
    @Log(title = "销售订单", businessType = BusinessType.DELETE)
    @PostMapping("del")
    public AjaxResult remove(Long id) {
        return rechargeService.del(id);
    }
}
